package com.example.learnquartz.api;

import com.example.learnquartz.bean.AjaxResult;
import com.example.learnquartz.entity.SysJob;
import com.example.learnquartz.entity.SysJobLog;
import com.example.learnquartz.service.ISysJobLogService;
import com.example.learnquartz.service.ISysJobService;
import com.example.learnquartz.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调度日志操作处理
 *
 * @author ruoyi
 */
@Controller
@RequestMapping("/monitor/jobLog")
public class SysJobLogController {


    @Autowired
    private ISysJobService jobService;

    @Autowired
    private ISysJobLogService jobLogService;

    @GetMapping()
    public AjaxResult jobLog(@RequestParam(value = "jobId", required = false) Long jobId) {
        if (StringUtils.isNotNull(jobId)) {
            SysJob job = jobService.selectJobById(jobId);
            return AjaxResult.success(job);

        }
        return AjaxResult.success();
    }

    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(SysJobLog jobLog) {
        List<SysJobLog> list = jobLogService.selectJobLogList(jobLog);
        return AjaxResult.success(list);
    }


    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return AjaxResult.success(jobLogService.deleteJobLogByIds(ids));
    }

    @GetMapping("/detail/{jobLogId}")
    public AjaxResult detail(@PathVariable("jobLogId") Long jobLogId) {
        return AjaxResult.success(jobLogService.selectJobLogById(jobLogId));
    }

    @PostMapping("/clean")
    @ResponseBody
    public AjaxResult clean() {
        jobLogService.cleanJobLog();
        return AjaxResult.success();
    }
}
